package main

import (
	"github.com/gin-gonic/gin"
	"io"
	"os"
)

func main() {
	r := gin.New()
	f, _ := os.Create("output.log")
	logger := io.MultiWriter(f)
	gin.DefaultWriter = logger
	gin.DefaultErrorWriter = logger

	r.Use(gin.Logger(), gin.Recovery())
	//r.Use(gin.Logger())  //使用recover()可以避免异常恐慌中断

	r.GET("/test", func(c *gin.Context) {
		name := c.DefaultQuery("name", "default_name")
		panic("error!") //模拟异常退出，使用gin.Recovery()可以使避免服务挂掉
		c.String(200, name)
		c.Abort()
	})
	_ = r.Run()
}
